﻿using DevExpress.XtraSplashScreen;
using System;
using XCI.Extensions;
using XCI.Sys.Helper;
using XCI.Sys.Model;
using XCI.Windows;
using XCI.Windows.Forms;
using XCI.Windows.Helper;

namespace XCI.Sys.Forms
{
    /// <summary>
    /// 系统报表标准视图模块
    /// </summary>
    [FormCaption("系统报表标准视图模块")]
    public partial class FrmReportStandardView : FrmBase
    {
        private AsyncWorker asyncWorker = new AsyncWorker();
        private IOverlaySplashScreenHandle handle = null;
        public FrmReportStandardView()
        {
            InitializeComponent();
        }

        private void FrmReportStandardView_Load(object sender, EventArgs e)
        {
            
            //工具栏
            if (ParamData.Get("toolbar", "1").Equals("0"))
            {
                previewBar1.Visible = false;
            }
            //状态栏
            if (ParamData.Get("statusbar", "1").Equals("0"))
            {
                previewBar2.Visible = false;
            }

            SysReport sysReport = null;
            asyncWorker.RunCallback(p =>
                {
                    try
                    {
                        handle = SplashHelper.ShowProgressPanel(SysRuntime.MainForm);
                        sysReport = ReportHelper.GetSysReportByParamData(ParamData);
                    }
                    catch
                    {
                        SplashHelper.CloseProgressPanel(handle);
                    }
                }).CompletCallback(p =>
                {
                    if (sysReport != null)
                    {
                        ReportObject.From(sysReport).View(documentViewer1, () =>
                        {
                            SplashHelper.CloseProgressPanel(handle);
                        });
                    }
                    else
                    {
                        SplashHelper.CloseProgressPanel(handle);
                    }
                }).RunAsync();

        }
    }
}
